<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Sunlight::District</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Sunlight::District</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/sunlight/district_rb.html">
                lib/sunlight/district.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="SunlightObject.html">
                SunlightObject
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000011">all_from_zipcode</a>&nbsp;&nbsp;
      <a href="#M000009">get</a>&nbsp;&nbsp;
      <a href="#M000010">get_from_lat_long</a>&nbsp;&nbsp;
      <a href="#M000008">new</a>&nbsp;&nbsp;
      <a href="#M000012">zipcodes_in</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">number</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">state</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">all_from_zipcode</span><span class="method-args">(zipcode)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Usage:
</p>
<pre>
  District.all_from_zipcode(90210)    # returns array of District objects
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
<span class="ruby-comment cmt"># File lib/sunlight/district.rb, line 68</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">all_from_zipcode</span>(<span class="ruby-identifier">zipcode</span>)
      
      <span class="ruby-identifier">url</span> = <span class="ruby-identifier">construct_url</span>(<span class="ruby-value str">&quot;districts.getDistrictsFromZip&quot;</span>, {<span class="ruby-identifier">:zip</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">zipcode</span>})
      
      <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">result</span> = <span class="ruby-identifier">get_json_data</span>(<span class="ruby-identifier">url</span>))
            
        <span class="ruby-identifier">districts</span> = []
        <span class="ruby-identifier">result</span>[<span class="ruby-value str">&quot;response&quot;</span>][<span class="ruby-value str">&quot;districts&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">district</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">districts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">District</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">district</span>[<span class="ruby-value str">&quot;district&quot;</span>][<span class="ruby-value str">&quot;state&quot;</span>], <span class="ruby-identifier">district</span>[<span class="ruby-value str">&quot;district&quot;</span>][<span class="ruby-value str">&quot;number&quot;</span>])
        <span class="ruby-keyword kw">end</span>
        
        <span class="ruby-identifier">districts</span>
      
      <span class="ruby-keyword kw">else</span>  
        <span class="ruby-keyword kw">nil</span>
      <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># if response.class</span>
      
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">get</span><span class="method-args">(params)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Usage:
</p>
<pre>
  District.get(:latitude =&gt; 33.876145, :longitude =&gt; -84.453789)    # returns one District object or nil
  District.get(:address =&gt; &quot;123 Fifth Ave New York, NY&quot;)     # returns one District object or nil
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
<span class="ruby-comment cmt"># File lib/sunlight/district.rb, line 17</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get</span>(<span class="ruby-identifier">params</span>)

      <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:latitude</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:longitude</span>])
        
        <span class="ruby-identifier">get_from_lat_long</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:latitude</span>], <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:longitude</span>])
        
      <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:address</span>])

        <span class="ruby-comment cmt"># get the lat/long from Google</span>
        <span class="ruby-identifier">placemarks</span> = <span class="ruby-constant">Geocoding</span><span class="ruby-operator">::</span><span class="ruby-identifier">get</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:address</span>])
        
        <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">placemarks</span>.<span class="ruby-identifier">empty?</span>
          <span class="ruby-identifier">placemark</span> = <span class="ruby-identifier">placemarks</span>[<span class="ruby-value">0</span>]
          <span class="ruby-identifier">get_from_lat_long</span>(<span class="ruby-identifier">placemark</span>.<span class="ruby-identifier">latitude</span>, <span class="ruby-identifier">placemark</span>.<span class="ruby-identifier">longitude</span>)
        <span class="ruby-keyword kw">end</span>

      <span class="ruby-keyword kw">else</span>
        <span class="ruby-keyword kw">nil</span> <span class="ruby-comment cmt"># appropriate params not found</span>
      <span class="ruby-keyword kw">end</span>
      
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">get_from_lat_long</span><span class="method-args">(latitude, longitude)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Usage:
</p>
<pre>
  District.get_from_lat_long(-123, 123)   # returns District object or nil
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
<span class="ruby-comment cmt"># File lib/sunlight/district.rb, line 44</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">get_from_lat_long</span>(<span class="ruby-identifier">latitude</span>, <span class="ruby-identifier">longitude</span>)
      
      <span class="ruby-identifier">url</span> = <span class="ruby-identifier">construct_url</span>(<span class="ruby-value str">&quot;districts.getDistrictFromLatLong&quot;</span>, {<span class="ruby-identifier">:latitude</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">latitude</span>, <span class="ruby-identifier">:longitude</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">longitude</span>})
      
      <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">result</span> = <span class="ruby-identifier">get_json_data</span>(<span class="ruby-identifier">url</span>))
            
        <span class="ruby-identifier">districts</span> = []
        <span class="ruby-identifier">result</span>[<span class="ruby-value str">&quot;response&quot;</span>][<span class="ruby-value str">&quot;districts&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">district</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">districts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">District</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">district</span>[<span class="ruby-value str">&quot;district&quot;</span>][<span class="ruby-value str">&quot;state&quot;</span>], <span class="ruby-identifier">district</span>[<span class="ruby-value str">&quot;district&quot;</span>][<span class="ruby-value str">&quot;number&quot;</span>])
        <span class="ruby-keyword kw">end</span>
      
        <span class="ruby-identifier">districts</span>.<span class="ruby-identifier">first</span>
        
      <span class="ruby-keyword kw">else</span>  
        <span class="ruby-keyword kw">nil</span>
      <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># if response.class</span>
    
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(state, number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
<span class="ruby-comment cmt"># File lib/sunlight/district.rb, line 7</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">state</span>, <span class="ruby-identifier">number</span>)
      <span class="ruby-ivar">@state</span> = <span class="ruby-identifier">state</span>
      <span class="ruby-ivar">@number</span> = <span class="ruby-identifier">number</span>
    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">zipcodes_in</span><span class="method-args">(state, number)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Usage:
</p>
<pre>
  District.zipcodes_in(&quot;NY&quot;, 29)     # returns [&quot;14009&quot;, &quot;14024&quot;, &quot;14029&quot;, ...]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
<span class="ruby-comment cmt"># File lib/sunlight/district.rb, line 92</span>
    <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">zipcodes_in</span>(<span class="ruby-identifier">state</span>, <span class="ruby-identifier">number</span>)
      
      <span class="ruby-identifier">url</span> = <span class="ruby-identifier">construct_url</span>(<span class="ruby-value str">&quot;districts.getZipsFromDistrict&quot;</span>, {<span class="ruby-identifier">:state</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">state</span>, <span class="ruby-identifier">:district</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">number</span>})
      
      <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">result</span> = <span class="ruby-identifier">get_json_data</span>(<span class="ruby-identifier">url</span>))
        <span class="ruby-identifier">result</span>[<span class="ruby-value str">&quot;response&quot;</span>][<span class="ruby-value str">&quot;zips&quot;</span>]
      <span class="ruby-keyword kw">else</span>  
        <span class="ruby-keyword kw">nil</span>
      <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># if response.class</span>

    <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>